@import org.silkframework.util.DPair
@import org.silkframework.workspace.Project
@import controllers.rules.routes.Assets

@(sources: DPair[String], paths: DPair[Seq[String]], onlySource: Boolean, loadingMsg: String = "", warning: String = "", project: Project)

<script type="text/javascript">
  // Initialization
  $(function() {
    // Make operators draggable
    $('.sourcePaths, .targetPaths').draggable({
      helper: function() {
        var box = $(this).children('.dragDiv');
        box.show();
        return box;
      } ,
      stop: function(event, ui) {
        ui.helper.hide();
        $.ui.ddmanager.current.cancelHelperRemoval = true;
      } 
      //containment: "#content"
    });

  })
</script>

@pathOperators(sources.source, paths.source, "Source")
@if(!onlySource) {
  @pathOperators(sources.target, paths.target, "Target")
}

@pathOperators(source: String, paths: Seq[String], pathType: String) = {
  <div class="palette-block">
    <div class="block-header clearfix">
      <span style='font-weight: bold; color: #582271;' class="path_type">@pathType Paths:</span>
      <span id='@{pathType.toLowerCase}_id' class="path_id">@source</span>
      <div class="mdl-tooltip mdl-tooltip--right" for="@{pathType.toLowerCase}_id">@source</div>
    </div>

    @*<div class="more">
      <span class='restriction'>
        <span style='font-weight: bold; float: left; padding-right: 5px; color: #582271;' class="path_type">Restriction: </span>
        <span id='@{pathType.toLowerCase}_restriction' class="path_id"></span>
      </span>
      <div style='clear: both;'></div>
    </div>*@

    <div class="scrollboxes">
      <div class="draggable @{pathType.toLowerCase}Paths">
        <span></span>
        <small></small>
        <p>(custom path)</p>
        @pathExpanded("", pathType)
      </div>

      @loadingMsg
      @if(!warning.isEmpty) { <img src="@Assets.at("img/exclamation.png")" style="cursor:help;" title="@warning"/> }

      @for(path <- paths) {
        <div id="path_@{pathType.toLowerCase}_@{java.net.URLEncoder.encode(path, "utf-8")}" class="draggable @{pathType.toLowerCase}Paths">
          <span></span>
          <p class="non-breaking-label">@path</p>
          @pathExpanded(path, pathType)
        </div>
        <div class="mdl-tooltip mdl-tooltip--right" for="path_@{pathType.toLowerCase}_@{java.net.URLEncoder.encode(path, "utf-8")}">@path</div>
      }
    </div>
  </div>
}

@pathExpanded(path: String, pathType: String) = {
  @pathBox(pathType.toLowerCase + "Path", pathType == "Source", path, 0, 0, false, project)
}